N = int(input())
binN = bin(N)
sN = (str(binN) + '-')[2:-1]  # 正常的二进制数字字符串
print(f'sN = {sN}')

N1 = 0  # 二进制的N中含几个1
for i in sN:
	if i == '1':
		N1 += 1
print(f'N1 = {N1}')

print()
I = N + 1
while True:  # 向上查找
	# 同样的操作(line2 ~ line3)
	binI = bin(I)
	sI = (str(binI) + '-')[2:-1]
	# 同line6 ~ line9
	I1 = 0
	for i in sI:
		if i == '1':
			I1 += 1
	
	print(f'I = {I}')
	print(f'sI = {sI}')
	print(f'I1 = {I1}')
	print()
	
	if N1 == I1:  # 若所含的“1”的量相等
		print(f'The final answer is {I}.')
		break
	else:
		I += 1
		continue
